package juan.happyge.plugin.myi.config;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@Service
@State(name = "MoYuIntegration", storages = {@Storage(value = "myi-plugin.xml")})
public class ConfigManage implements PersistentStateComponent<ConfigManage> {

    private static ConfigManage configManage;

    public static ConfigManage getInstance(){
        if(configManage == null){
            configManage = ApplicationManager.getApplication().getService(ConfigManage.class);
        }
        return configManage;
    }


    @Nullable
    @Override
    public ConfigManage getState() {
        return configManage;
    }

    @Override
    public void loadState(@NotNull ConfigManage configManage) {
        bookConfig = configManage.getBookConfig();
    }

    private BookConfig bookConfig = new BookConfig();

    public void setBookConfig(BookConfig bookConfig) {
        this.bookConfig = bookConfig;
    }

    public BookConfig getBookConfig() {
        return bookConfig;
    }

}
